Skip to content

fix: add acceptance tests for smart cdn v2 - #1670

Open
itslenny wants to merge 1 commit into
masterfrom
lenny-temp/acceptance-manual-purge-cdn
Open

itslenny wants to merge 1 commit into
masterfrom
lenny-temp/acceptance-manual-purge-cdn

Conversation

@itslenny

@itslenny itslenny commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

What kind of change does this PR introduce?

Adds more test coverage for CDN behavior and support for Smart CDN V2 differences

Adds ACCEPTANCE_CDN_NEEDS_PURGE (default false) to manual purge cache where the storage service will be expected to actively purge in the future. This can be removed once #1772 is deployed and enabled.

Adds ACCEPTANCE_CDN_VERSION (default V1) to allow checking V2 specific expectations and timing. This can be removed once all projects are migrated to V2.

Adds cache key edge cases which includes cache keys that cannot be purged with Smart CDN V1. These tests fail against V1 projects and pass when run on projects using Smart CDN V2.

Adds test that creates/rotates signing keys across both supported algorithms and confirms CDN behavior for both. Asymmetric keys should share cache, symmetric must not. This test cannot currently clean up after itself because there is no delete jwk endpoint (I'll add one before we enable this test)

@itslenny
itslenny force-pushed the lenny-temp/acceptance-manual-purge-cdn branch from 199cff0 to 4b2d028 Compare November 5, 2026 19:05
@coveralls

coveralls commented Nov 5, 2026 •

Copy link
Copy Markdown

Coverage Report for CI Build 47369392798

Coverage decreased (-0.02%) to 88.868%

Details

  • Coverage decreased (-0.02%) from the base build.
  • Patch coverage: 2 uncovered changes across 1 file (4 of 6 lines covered, 66.67%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
acceptance/support/config.ts 6 4 66.67%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 19653
Covered Lines: 17992
Line Coverage: 91.55%
Relevant Branches: 12373
Covered Branches: 10469
Branch Coverage: 84.61%
Branches in Coverage %: Yes
Coverage Strength: 1276.46 hits per line

💛 - Coveralls

@itslenny
itslenny force-pushed the lenny-temp/acceptance-manual-purge-cdn branch 3 times, most recently from 8d61b87 to b51fc90 Compare November 11, 2026 17:29
@itslenny
itslenny force-pushed the lenny-temp/acceptance-manual-purge-cdn branch 4 times, most recently from 8c3ed0c to 1d8b632 Compare November 29, 2026 22:10
@itslenny
itslenny marked this pull request as ready for review November 29, 2026 22:23
@itslenny
itslenny requested a review from a team as a code owner November 29, 2026 22:23

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Findings marked 🟡 are optional suggestions and need no follow-up push.

Additional findings (outside the current diff — GitHub can't attach inline comments there):

  • 🟡 acceptance/support/cdn-purge.ts — Core and versioning suites with no CDN requirement can fail outright when ACCEPTANCE_CDN_NEEDS_PURGE=true is set against a target with no CDN. The helper checks only cdnNeedsManualPurge, never capabilities.cdn. It then sends DELETE /cdn with expectedStatus: 200, and that fails when no purge endpoint is configured. Fix: skip the purge unless both cdnNeedsManualPurge and capabilities.cdn are true. This covers the new callers in rest-extended.test.ts (profile 'core') and rest-object-versioning.test.ts (requires only 'versioning').

    Why this was flagged

    Trigger: an operator sets ACCEPTANCE_CDN_NEEDS_PURGE=true (for example in a shared CI env) and runs against a target where ACCEPTANCE_ENABLE_CDN is not set, such as the local target. The helper at cdn-purge.ts:43-47 calls purgeCdnCache, which sends DELETE /cdn/... with expectedStatus: 200 and retries: 3 (cdn-purge.ts:532-536). It also calls requireServiceKey(). This diff adds unconditional calls to it in rest-extended.test.ts:479 and :791 (describe profiles: ['core'], no cdn requirement) and in rest-object-versioning.test.ts (requires: ['versioning'] only). Those tests never touch the CDN on the base branch. After this change they fail with 'Unexpected HTTP status for DELETE .../cdn/...' whenever the server has no CDN purge endpoint configured (src/storage/cdn/cdn-cache-manager.test.ts:254 tests the cdnPurgeEndpointURL: undefined case). The capabilities.cdn flag (config.ts:184) exists to gate exactly this, but the helper does not consult it.

    Verification: In acceptance/support/cdn-purge.ts, purgeCdnCacheIfNeeded (lines 43-47) checks only if (getAcceptanceConfig().cdnNeedsManualPurge), and purgeCdnCache (lines 34-38) sends DELETE /cdn/... with expectedStatus: 200. config.ts:129 never ties it to cdnEnabled (config.ts:171). The diff calls the helper from rest-extended.test.ts:479 and rest-object-versioning.test.ts:463, which then fail. Hence nit.

Comment thread acceptance/specs/cdn.test.ts Resolved
{ versionId: a.version }
)
const historical = await client.request('GET', historicalRoute, {
expectedCacheStatus: isSigned ? 'MISS' : 'HIT',

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Signed-URL versioning tests will fail on any V2 edge that verifies signed tokens itself, even though the CDN is behaving correctly. They hard-code a MISS for a later signed token on an etag that is already warm. cdn.test.ts:901-917 shows such tokens share the object-level entry and return HIT. Fix: read x-smart-cdn-access from the warm-up response and expect HIT when it is signed-verified, as cdn.test.ts does, which covers the 3 sites listed. Same pattern at 3 sites (cdn-object-versioning.test.ts:127, :226, :286).

Why this was flagged

The trigger is a V2 project whose edge verifies signed tokens, so responses carry x-smart-cdn-access: signed-verified. cdn.test.ts:901-910 already treats that case as valid: a second signed token for the same object gets a HIT on the entry the first token warmed. cdn-object-versioning.test.ts:127 requests current, which resolves to etag B after routeB was warmed, and expects isSigned ? 'MISS' : 'HIT'. Lines 226 and 286 send historical versionId requests for etag A after the current route warmed A, with the same expectation. On such an edge every attempt returns HIT, and the client throws Unexpected cache status after CACHE_RETRIES (15) attempts. So the signed suite fails even though the CDN behaves as designed. These tests are new, so the base branch has nothing to compare against. Retries do not help because each attempt keeps returning HIT.

Verification: Trigger: a Smart CDN V2 project whose edge verifies signed tokens, so responses carry x-smart-cdn-access: signed-verified. cdn.test.ts:901-910 then expects a second signed token to get 'HIT'. cdn-object-versioning.test.ts makes no such check, so line 127 always expects isSigned ? 'MISS' : 'HIT', as do lines 226 and 286. http.ts (lines 102-113) throws on a mismatch, so all 15 CACHE_RETRIES fail.

Comment thread acceptance/support/config.ts Resolved
Comment on lines +30 to +32
} else if (versionId) {
url += '?versionId=' + encodeURIComponent(versionId)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 (optional) Against this repo's storage server, version-scoped purges clear the whole object, so both V2 per-version purge tests fail. The helper sends ?versionId= to DELETE /cdn/:bucket/*. But purgeQuerySchema (src/http/routes/cdn/purgeCache.ts:25) only declares transformations, so the handler ignores it. Fix: add versionId support to the purge route in this change, or gate both tests on a server that has it. The tests sit at cdn-object-versioning.test.ts:370 and :416.

Why this was flagged

The trigger is a run with ACCEPTANCE_CDN_VERSION=2 against a server built from this checkout. In 'purges only the targeted version...', purgeCdnCache(client, { bucketName, objectKey, versionId: a }) at cdn-object-versioning.test.ts:370 builds /cdn/<bucket>/<key>?versionId=.... The /:bucketName/* handler in src/http/routes/cdn/purgeCache.ts:123-133 reads only transformations and calls cdnCache.purge({ type: 'object', ... }). That purges every cached entry for the object. The hitB and hitCurrent requests run with no retries and expect 'HIT', so they get MISS and the test fails. With ACCEPTANCE_CDN_NEEDS_PURGE=true, the same thing happens at :416 in the auto-purge test, so the stillCurrent HIT assertion fails. No guard catches the unknown query param. The schema has no additionalProperties:false, so the server ignores it and still returns 200 'success'.

Verification: nit. The trigger is a run with ACCEPTANCE_CDN_VERSION=2 against a storage server built from this checkout. On the server, purgeQuerySchema (src/http/routes/cdn/purgeCache.ts:25-30) declares only transformations. So a version-scoped purge is sent upstream as a purge of the whole object. Nothing in the diff adds versionId support to the server route.

Comment thread acceptance/specs/cdn.test.ts Resolved
Comment thread acceptance/specs/cdn.test.ts Resolved
Comment thread acceptance/support/config.ts Resolved
@itslenny
itslenny force-pushed the lenny-temp/acceptance-manual-purge-cdn branch from 1d8b632 to 898f66d Compare December 4, 2026 15:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants